package com.yuerlive.rainbow.module.game.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;

import com.yuerlive.rainbow.R;
import com.yuerlive.rainbow.entity.NiuniuHistory;

import java.util.List;

/**
 * Created by xiaoyi on 2017/6/4.
 */

public class NiuNiuHistoryAdapter extends BaseAdapter {
    private List<NiuniuHistory> mDatas;
    private Context context;

    public NiuNiuHistoryAdapter(Context context, List<NiuniuHistory> mDatas) {
        this.mDatas = mDatas;
        this.context = context;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_nn_history_item, null);
            holder = new ViewHolder();
            holder.left = (ImageView) convertView.findViewById(R.id.ivLeft);
            holder.center = (ImageView) convertView.findViewById(R.id.ivCenter);
            holder.right = (ImageView) convertView.findViewById(R.id.ivRight);
            holder.resultNew = (ImageView) convertView.findViewById(R.id.ivNew);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        NiuniuHistory history = mDatas.get(position);
        holder.left.setImageResource(history.getIndex1Win() == 0 ? R.drawable.result_nn_lose : R.drawable.result_nn_wins);
        holder.center.setImageResource(history.getIndex2Win() == 0 ? R.drawable.result_nn_lose : R.drawable.result_nn_wins);
        holder.right.setImageResource(history.getIndex3Win() == 0 ? R.drawable.result_nn_lose : R.drawable.result_nn_wins);
        if (position == 0) {
            holder.resultNew.setVisibility(View.VISIBLE);
        } else {
            holder.resultNew.setVisibility(View.GONE);
        }

        return convertView;
    }

    static class ViewHolder {
        ImageView left;
        ImageView center;
        ImageView right;
        ImageView resultNew;
    }
}
